package com.example.work4.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.example.work4.BR
import com.example.work4.R
import com.example.work4.adapter.viewHolder.ChatViewHolder
import com.example.work4.adapter.viewHolder.FriendBaseDataViewHolder
import com.example.work4.common.ImageUtil
import com.example.work4.http.data.FriendList
import com.example.work4.po.SSOInfo

class FriendListAdapter(var data:List<FriendList.FriendBaseData>):
    RecyclerView.Adapter<FriendBaseDataViewHolder>() {
    var context: Context? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendBaseDataViewHolder {
        context = parent.context
        return FriendBaseDataViewHolder(
            DataBindingUtil.inflate(
                LayoutInflater.from(parent.context),
                viewType,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: FriendBaseDataViewHolder, position: Int) {
        val binding : ViewDataBinding = holder.dataBinding
        val imgUtil = ImageUtil(context!!)
        var curData = data[position]
        if(curData.id == SSOInfo.id){
            holder.button.visibility = View.INVISIBLE
            holder.chat.visibility = View.INVISIBLE
        }
        holder.data = curData
        imgUtil.GlideLoadCenterCrop(curData.avatar,holder.avatar)
        binding.setVariable(BR.baseData, curData)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun getItemViewType(position: Int): Int {
        return R.layout.item_friendbasedata
    }

}